package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.RecruitmentResume;
import com.ruoyi.system.mapper.RecruitmentResumeMapper;
import com.ruoyi.system.mapper.ResumeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RecruitmentMapper;
import com.ruoyi.system.domain.Recruitment;
import com.ruoyi.system.service.IRecruitmentService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 招聘管理Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-01
 */
@Service
public class RecruitmentServiceImpl implements IRecruitmentService
{
    @Resource
    private RecruitmentMapper recruitmentMapper;

    @Resource
    private RecruitmentResumeMapper recruitmentResumeMapper;

    /**
     * 查询招聘管理
     *
     * @param recruitmentId 招聘管理主键
     * @return 招聘管理
     */
    @Override
    public Recruitment selectRecruitmentByRecruitmentId(Long recruitmentId)
    {
        return recruitmentMapper.selectRecruitmentByRecruitmentId(recruitmentId);
    }

    /**
     * 查询招聘信息
     *
     * @param recruitmentName 招聘信息主键
     * @return 招聘信息
     */
    @Override
    public Recruitment selectRecruitmentByRecruitmentName(String recruitmentName)
    {
        return recruitmentMapper.selectRecruitmentByRecruitmentName(recruitmentName);
    }

    /**
     * 查询招聘管理列表
     *
     * @param recruitment 招聘管理
     * @return 招聘管理
     */
    @Override
    public List<Recruitment> selectRecruitmentList(Recruitment recruitment)
    {
        return recruitmentMapper.selectRecruitmentList(recruitment);
    }

    /**
     * 新增招聘管理
     *
     * @param recruitment 招聘管理
     * @return 结果
     */
    @Override
    public int insertRecruitment(Recruitment recruitment)
    {
        recruitment.setCreateTime(DateUtils.getNowDate());
        return recruitmentMapper.insertRecruitment(recruitment);
    }

    /**
     * 修改招聘管理
     *
     * @param recruitment 招聘管理
     * @return 结果
     */
    @Override
    public int updateRecruitment(Recruitment recruitment)
    {
        recruitment.setUpdateTime(DateUtils.getNowDate());
        return recruitmentMapper.updateRecruitment(recruitment);
    }

    /**
     * 批量删除招聘管理
     *
     * @param recruitmentIds 需要删除的招聘管理主键
     * @return 结果
     */
    @Override
    public int deleteRecruitmentByRecruitmentIds(String recruitmentIds)
    {
        return recruitmentMapper.deleteRecruitmentByRecruitmentIds(Convert.toStrArray(recruitmentIds));
    }

    /**
     * 删除招聘管理信息
     *
     * @param recruitmentId 招聘管理主键
     * @return 结果
     */
    @Override
    public int deleteRecruitmentByRecruitmentId(Long recruitmentId)
    {
        return recruitmentMapper.deleteRecruitmentByRecruitmentId(recruitmentId);
    }

    /**
     * 发送简历
     * @param recruitmentId 招聘信息id
     * @param resumeId 简历id
     * @return
     */
    @Override
    public int giveRecruitment(String recruitmentId, String resumeId) {
        //发送简历
        Recruitment recruitment = recruitmentMapper.selectRecruitmentByRecruitmentId(Long.valueOf(recruitmentId));
        RecruitmentResume recruitmentResume = new RecruitmentResume();
        recruitmentResume.setRecruitmentId(Long.valueOf(recruitmentId));
        recruitmentResume.setResumeId(Long.valueOf(resumeId));
        recruitmentResume.setRecruitmentName(recruitment.getRecruitmentName());
        recruitmentResume.setFlag(0);
        return recruitmentResumeMapper.insertRecruitmentResume(recruitmentResume);
    }
}
